home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 1995 #5 & #6 / Amiga Plus CD - 1995 - No. 5 and 6.iso / pd / netz / amyboard / xboard-3.3.pl0 / xedittags.c < prev    next >
C/C++ Source or Header  |  1995-08-12  |  11KB  |  403 lines

  1. /*
  2.  * xedittags.c -- Tags edit window, part of X front end for XBoard
  3.  * $Id: xedittags.c,v 1.3 1995/07/28 05:23:42 mann Exp $
  4.  *
  5.  * Copyright 1995 Free Software Foundation, Inc.
  6.  *
  7.  * The following terms apply to the enhanced version of XBoard distributed
  8.  * by the Free Software Foundation:
  9.  * ------------------------------------------------------------------------
  10.  * This program is free software; you can redistribute it and/or modify
  11.  * it under the terms of the GNU General Public License as published by
  12.  * the Free Software Foundation; either version 2 of the License, or
  13.  * (at your option) any later version.
  14.  *
  15.  * This program is distributed in the hope that it will be useful,
  16.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18.  * GNU General Public License for more details.
  19.  *
  20.  * You should have received a copy of the GNU General Public License
  21.  * along with this program; if not, write to the Free Software
  22.  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  23.  * ------------------------------------------------------------------------
  24.  *
  25.  * See the file ChangeLog for a revision history.
  26.  */
  27.  
  28. #include <config.h>
  29.  
  30. #include <stdio.h>
  31. #include <ctype.h>
  32. #include <errno.h>
  33. #include <sys/types.h>
  34.  
  35. #if STDC_HEADERS
  36. # include <stdlib.h>
  37. # include <string.h>
  38. #else /* not STDC_HEADERS */
  39. extern char *getenv();
  40. # if HAVE_STRING_H
  41. #  include <string.h>
  42. # else /* not HAVE_STRING_H */
  43. #  include <strings.h>
  44. # endif /* not HAVE_STRING_H */
  45. #endif /* not STDC_HEADERS */
  46.  
  47. #if HAVE_UNISTD_H
  48. # include <unistd.h>
  49. #endif
  50.  
  51. #include <X11/Intrinsic.h>
  52. #include <X11/StringDefs.h>
  53. #include <X11/Shell.h>
  54. #include <X11/Xaw/Dialog.h>
  55. #include <X11/Xaw/Form.h>
  56. #include <X11/Xaw/List.h>
  57. #include <X11/Xaw/Label.h>
  58. #include <X11/Xaw/SimpleMenu.h>
  59. #include <X11/Xaw/SmeBSB.h>
  60. #include <X11/Xaw/SmeLine.h>
  61. #include <X11/Xaw/Box.h>
  62. #include <X11/Xaw/MenuButton.h>
  63. #include <X11/cursorfont.h>
  64. #include <X11/Xaw/Text.h>
  65. #include <X11/Xaw/AsciiText.h>
  66. #include <X11/Xaw/Viewport.h>
  67.  
  68. #include "common.h"
  69. #include "frontend.h"
  70. #include "backend.h"
  71. #include "xboard.h"
  72. #include "xedittags.h"
  73.  
  74. extern Widget formWidget, shellWidget, boardWidget, menuBarWidget;
  75. extern Display *xDisplay;
  76. extern int squareSize;
  77. extern Pixmap xMarkPixmap;
  78.  
  79. Position tagsX = -1, tagsY = -1;
  80. int tagsUp = False, editTagsUp = False;
  81. Widget tagsShell, editTagsShell;
  82.  
  83. void TagsCallback(w, client_data, call_data)
  84.      Widget w;
  85.      XtPointer client_data, call_data;
  86. {
  87.     String name;
  88.     Arg args[16];
  89.     int j;
  90.  
  91.     j = 0;
  92.     XtSetArg(args[j], XtNlabel, &name);  j++;
  93.     XtGetValues(w, args, j);
  94.  
  95.     if (strcmp(name, "close") == 0) {
  96.     TagsPopDown();
  97.     } else if (strcmp(name, "edit") == 0) {
  98.     TagsPopDown();
  99.     EditTagsEvent();
  100.     }
  101. }
  102.  
  103.  
  104. void EditTagsCallback(w, client_data, call_data)
  105.      Widget w;
  106.      XtPointer client_data, call_data;
  107. {
  108.     String name, val;
  109.     Arg args[16];
  110.     int j;
  111.     Widget textw;
  112.  
  113.     j = 0;
  114.     XtSetArg(args[j], XtNlabel, &name);  j++;
  115.     XtGetValues(w, args, j);
  116.  
  117.     if (strcmp(name, "ok") == 0) {
  118.     textw = XtNameToWidget(editTagsShell, "form.text");
  119.     j = 0;
  120.     XtSetArg(args[j], XtNstring, &val); j++;
  121.     XtGetValues(textw, args, j);
  122.     ReplaceTags(val, &gameInfo);
  123.     TagsPopDown();
  124.     } else if (strcmp(name, "cancel") == 0) {
  125.     TagsPopDown();
  126.     } else if (strcmp(name, "clear") == 0) {
  127.     textw = XtNameToWidget(editTagsShell, "form.text");
  128.     XtCallActionProc(textw, "select-all", NULL, NULL, 0);
  129.     XtCallActionProc(textw, "kill-selection", NULL, NULL, 0);
  130.     }
  131. }
  132.  
  133. Widget TagsCreate(name, text, msg, mutable, callback)
  134.      char *name, *text, *msg;
  135.      int /*Boolean*/ mutable;
  136.      XtCallbackProc callback;
  137. {
  138.     Arg args[16];
  139.     Widget shell, form, textw, msgw;
  140.     Widget b_ok, b_cancel, b_close, b_edit, b;
  141.     Dimension bw_width, pw_width;
  142.     Dimension pw_height;
  143.     int j, xx, yy;
  144.     Window junk;
  145.  
  146.     j = 0;
  147.     XtSetArg(args[j], XtNwidth, &bw_width);  j++;
  148.     XtGetValues(boardWidget, args, j);
  149.  
  150.     j = 0;
  151.     XtSetArg(args[j], XtNresizable, True);  j++;
  152. #if TOPLEVEL
  153.     shell =
  154.       XtCreatePopupShell(name, topLevelShellWidgetClass,
  155.              shellWidget, args, j);
  156. #else
  157.     shell =
  158.       XtCreatePopupShell(name, transientShellWidgetClass,
  159.              shellWidget, args, j);
  160. #endif
  161.     j = 0;
  162.     form =
  163.       XtCreateManagedWidget("form", formWidgetClass, shell, args, j);
  164.  
  165.     j = 0;
  166.     if (mutable) {
  167.     XtSetArg(args[j], XtNeditType, XawtextEdit);  j++;
  168.     XtSetArg(args[j], XtNuseStringInPlace, False);  j++;
  169.     }
  170.     XtSetArg(args[j], XtNstring, text);  j++;
  171.     XtSetArg(args[j], XtNtop, XtChainTop);  j++;
  172.     XtSetArg(args[j], XtNbottom, XtChainBottom);  j++;
  173.     XtSetArg(args[j], XtNleft, XtChainLeft);  j++;
  174.     XtSetArg(args[j], XtNright, XtRubber);  j++;
  175.     XtSetArg(args[j], XtNresizable, True);  j++;
  176.     XtSetArg(args[j], XtNwidth, bw_width/2);  j++;
  177.     XtSetArg(args[j], XtNheight, bw_width/3);  j++;
  178.     XtSetArg(args[j], XtNscrollVertical, XawtextScrollWhenNeeded);  j++;
  179.     XtSetArg(args[j], XtNautoFill, False);  j++;
  180.     textw =
  181.       XtCreateManagedWidget("text", asciiTextWidgetClass, form, args, j);
  182.  
  183.     if (cmailMsgLoaded && !mutable) {
  184.     j = 0;
  185.     XtSetArg(args[j], XtNfromVert, textw);  j++;
  186.     XtSetArg(args[j], XtNtop, XtChainBottom); j++;
  187.     XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
  188.     XtSetArg(args[j], XtNleft, XtChainLeft); j++;
  189.     XtSetArg(args[j], XtNright, XtChainRight); j++;
  190.     XtSetArg(args[j], XtNborderWidth, 0); j++;
  191.     XtSetArg(args[j], XtNjustify, XtJustifyLeft); j++;
  192.     XtSetArg(args[j], XtNlabel, msg); j++;
  193.     msgw =
  194.       XtCreateManagedWidget("msg", labelWidgetClass, form, args, j);
  195.     } else {
  196.     msgw = textw;
  197.     }
  198.     if (mutable) {
  199.     j = 0;
  200.     XtSetArg(args[j], XtNfromVert, msgw);  j++;
  201.     XtSetArg(args[j], XtNtop, XtChainBottom); j++;
  202.     XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
  203.     XtSetArg(args[j], XtNleft, XtChainLeft); j++;
  204.     XtSetArg(args[j], XtNright, XtChainLeft); j++;
  205.     b_ok = b =
  206.       XtCreateManagedWidget("ok", commandWidgetClass, form, args, j);
  207.     XtAddCallback(b_ok, XtNcallback, callback, (XtPointer) 0);
  208.  
  209.     j = 0;
  210.     XtSetArg(args[j], XtNfromVert, msgw);  j++;
  211.     XtSetArg(args[j], XtNfromHoriz, b);  j++;
  212.     XtSetArg(args[j], XtNtop, XtChainBottom); j++;
  213.     XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
  214.     XtSetArg(args[j], XtNleft, XtChainLeft); j++;
  215.     XtSetArg(args[j], XtNright, XtChainLeft); j++;
  216.     b_cancel = b =
  217.       XtCreateManagedWidget("cancel", commandWidgetClass, form, args, j);
  218.     XtAddCallback(b_cancel, XtNcallback, callback, (XtPointer) 0);
  219.  
  220. #if 0
  221.     j = 0;
  222.     XtSetArg(args[j], XtNfromVert, msgw);  j++;
  223.     XtSetArg(args[j], XtNfromHoriz, b);  j++;
  224.     XtSetArg(args[j], XtNtop, XtChainBottom); j++;
  225.     XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
  226.     XtSetArg(args[j], XtNleft, XtChainLeft); j++;
  227.     XtSetArg(args[j], XtNright, XtChainLeft); j++;
  228.     b_clear = b =
  229.       XtCreateManagedWidget("clear", commandWidgetClass, form, args, j);
  230.     XtAddCallback(b_clear, XtNcallback, callback, (XtPointer) 0);
  231. #endif
  232.     } else {
  233.     j = 0;
  234.     XtSetArg(args[j], XtNfromVert, msgw);  j++;
  235.     XtSetArg(args[j], XtNtop, XtChainBottom); j++;
  236.     XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
  237.     XtSetArg(args[j], XtNleft, XtChainLeft); j++;
  238.     XtSetArg(args[j], XtNright, XtChainLeft); j++;
  239.     b_close = b =
  240.       XtCreateManagedWidget("close", commandWidgetClass, form, args, j);
  241.     XtAddCallback(b_close, XtNcallback, callback, (XtPointer) 0);
  242.  
  243.     j = 0;
  244.     XtSetArg(args[j], XtNfromVert, msgw);  j++;
  245.     XtSetArg(args[j], XtNfromHoriz, b);  j++;
  246.     XtSetArg(args[j], XtNtop, XtChainBottom); j++;
  247.     XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
  248.     XtSetArg(args[j], XtNleft, XtChainLeft); j++;
  249.     XtSetArg(args[j], XtNright, XtChainLeft); j++;
  250.     b_edit = b =
  251.       XtCreateManagedWidget("edit", commandWidgetClass, form, args, j);
  252.     XtAddCallback(b_edit, XtNcallback, callback, (XtPointer) 0);
  253.     }
  254.  
  255.     XtRealizeWidget(shell);
  256.  
  257.     if (tagsX == -1) {
  258.     j = 0;
  259.     XtSetArg(args[j], XtNwidth, &bw_width);  j++;
  260.     XtGetValues(boardWidget, args, j);
  261.     j = 0;
  262.     XtSetArg(args[j], XtNwidth, &pw_width);  j++;
  263.     XtSetArg(args[j], XtNheight, &pw_height);  j++;
  264.     XtGetValues(shell, args, j);
  265.  
  266. #ifdef NOTDEF
  267.     /* This code seems to tickle an X bug if it is executed too soon
  268.        after xboard starts up.  The coordinates get transformed as if
  269.        the main window was positioned at (0, 0).
  270.        */
  271.     XtTranslateCoords(boardWidget, (bw_width - pw_width) / 2,
  272.               0 - pw_height + squareSize / 3, &x, &y);
  273. #else
  274.     XTranslateCoordinates(xDisplay, XtWindow(boardWidget),
  275.                   RootWindowOfScreen(XtScreen(boardWidget)),
  276.                   (bw_width - pw_width) / 2,
  277.                   0 - pw_height + squareSize / 3, &xx, &yy, &junk);
  278.     tagsX = xx;
  279.     tagsY = yy;
  280. #endif
  281.     }
  282.     j = 0;
  283.     XtSetArg(args[j], XtNx, tagsX - appData.borderXoffset);  j++;
  284.     XtSetArg(args[j], XtNy, tagsY - appData.borderYoffset);  j++;
  285.     XtSetValues(shell, args, j);
  286.  
  287.     return shell;
  288. }
  289.  
  290.  
  291. void TagsPopUp(tags, msg)
  292.      char *tags, *msg;
  293. {
  294.     Arg args[16];
  295.     int j;
  296.     Widget textw, msgw;
  297.  
  298.     if (editTagsUp) TagsPopDown();
  299.     if (tagsShell == NULL) {
  300.     tagsShell =
  301.       TagsCreate("Tags", tags, msg, False, TagsCallback);
  302.     } else {
  303.     textw = XtNameToWidget(tagsShell, "form.text");
  304.     j = 0;
  305.     XtSetArg(args[j], XtNstring, tags); j++;
  306.     XtSetValues(textw, args, j);
  307.     j = 0;
  308.     XtSetArg(args[j], XtNiconName, (XtArgVal) "Tags");  j++;
  309.     XtSetArg(args[j], XtNtitle, (XtArgVal) "Tags");  j++;
  310.     XtSetValues(tagsShell, args, j);
  311.     msgw = XtNameToWidget(tagsShell, "form.msg");
  312.     if (msgw) {
  313.         j = 0;
  314.         XtSetArg(args[j], XtNlabel, msg); j++;
  315.         XtSetValues(msgw, args, j);
  316.     }
  317.     }
  318.  
  319.     XtPopup(tagsShell, XtGrabNone);
  320.     XSync(xDisplay, False);
  321.  
  322.     tagsUp = True;
  323.     j = 0;
  324.     XtSetArg(args[j], XtNleftBitmap, None); j++;
  325.     XtSetValues(XtNameToWidget(menuBarWidget, "menuMode.Edit Tags"),
  326.         args, j);
  327. }
  328.  
  329.  
  330. void EditTagsPopUp(tags)
  331.      char *tags;
  332. {
  333.     Widget textw;
  334.     Arg args[16];
  335.     int j;
  336.  
  337.     if (tagsUp) TagsPopDown();
  338.     if (editTagsShell == NULL) {
  339.     editTagsShell =
  340.       TagsCreate("Edit Tags", tags, NULL, True, EditTagsCallback); 
  341.     } else {
  342.     textw = XtNameToWidget(editTagsShell, "form.text");
  343.     j = 0;
  344.     XtSetArg(args[j], XtNstring, tags); j++;
  345.     XtSetValues(textw, args, j);
  346.     j = 0;
  347.     XtSetArg(args[j], XtNiconName, (XtArgVal) "Edit Tags");  j++;
  348.     XtSetArg(args[j], XtNtitle, (XtArgVal) "Edit Tags");  j++;
  349.     XtSetValues(editTagsShell, args, j);
  350.     }
  351.  
  352.     XtPopup(editTagsShell, XtGrabNone);
  353.     XtSetKeyboardFocus(shellWidget, editTagsShell);
  354.  
  355.     editTagsUp = True;
  356.     j = 0;
  357.     XtSetArg(args[j], XtNleftBitmap, xMarkPixmap); j++;
  358.     XtSetValues(XtNameToWidget(menuBarWidget, "menuMode.Edit Tags"),
  359.         args, j);
  360. }
  361.  
  362. void TagsPopDown()
  363. {
  364.     Arg args[16];
  365.     int j;
  366.     Widget w;
  367.  
  368.     if (tagsUp) {
  369.     w = tagsShell;
  370.     } else if (editTagsUp) {
  371.     w = editTagsShell;
  372.     } else {
  373.     return;
  374.     }
  375.     j = 0;
  376.     XtSetArg(args[j], XtNx, &tagsX); j++;
  377.     XtSetArg(args[j], XtNy, &tagsY); j++;
  378.     XtGetValues(w, args, j);
  379.     XtPopdown(w);
  380.     XtSetKeyboardFocus(shellWidget, formWidget);
  381.     XSync(xDisplay, False);
  382.     tagsUp = editTagsUp = False;
  383.     j = 0;
  384.     XtSetArg(args[j], XtNleftBitmap, None); j++;
  385.     XtSetValues(XtNameToWidget(menuBarWidget, "menuMode.Edit Tags"),
  386.         args, j);
  387. }
  388.  
  389. void
  390. EditTagsProc(w, event, prms, nprms)
  391.      Widget w;
  392.      XEvent *event;
  393.      String *prms;
  394.      Cardinal *nprms;
  395. {
  396.     if (tagsUp) TagsPopDown();
  397.     if (editTagsUp) {
  398.     TagsPopDown();
  399.     } else {
  400.     EditTagsEvent();
  401.     }
  402. }
  403.